define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pro/news/index',
                    add_url: 'pro/news/add',
                    edit_url: 'pro/news/edit',
                    del_url: 'pro/news/del',
                    multi_url: 'pro/news/multi',
                    table: 'gzns_news',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'cover', title: __('Cover'), formatter: Table.api.formatter.image,operate:false},
                        {field: 'title', title: __('Title')},
                        // {field: 'admin_id', title: __('Admin_id')},
                        {field: 'admin.nickname', title: __('admin_id'),operate:'Like'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'), "3":__('Status 3'), "4":__('Status 4'), "2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'enabled', title: __('Enabled'), searchList: {"0":__('Enabled 0'),"1":__('Enabled 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'weight', title: __('Weight'), operate:false},

                        {field: 'operate', title: __('Operate'),
                          table: table,
                          events: Table.api.events.operate,
                          formatter: Table.api.formatter.operate,
                          buttons: [
                            {
                              name: 'submit_check',
                              text: __('提交审核'),
                              title: __('提交审核'),
                              classname: 'btn btn-xs btn-success btn-ajax',
                              confirm: '确定提交审核吗？',
                              url: 'pro/news/submitCheck',
                              visible: function (row) {
                                return row.status == 1;
                              },
                              success: function () {
                                table.bootstrapTable('refresh');
                              }
                            },
                            {
                              name: 'check_result',
                              text: __('审核结果'),
                              title: __('审核结果'),
                              classname: 'btn btn-xs btn-success btn-dialog',
                              url: 'pro/news/showCheckResult',
                              visible: function (row) {
                                return row.status == 3 || row.status == 4;
                              }
                            }
                          ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
              $(".btn-editone,.btn-edit,.btn-add").data("area", ["100%", "100%"]);
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
